const TOKEN_KEY = 'ai-rewrites-tool-token'

const isLogin = () => {
  return !!localStorage.getItem(TOKEN_KEY)
}

const getToken = () => {
  return localStorage.getItem(TOKEN_KEY)
}

const setToken = (token: string) => {
  localStorage.setItem(TOKEN_KEY, token)
}

const clearToken = () => {
  localStorage.removeItem(TOKEN_KEY)
}
// userInfo
const USER_INFO_KEY = 'ai-rewrites-tool-userInfo'

const getUserInfo = () => {
  return JSON.parse(localStorage.getItem(USER_INFO_KEY) || '{}')
}

const setUserInfo = (userInfo: any) => {
  localStorage.setItem(USER_INFO_KEY, JSON.stringify(userInfo))
}

const clearUserInfo = () => {
  localStorage.removeItem(USER_INFO_KEY)
}
export { isLogin, getToken, setToken, clearToken, getUserInfo, setUserInfo, clearUserInfo }
